import { createRouter, createWebHistory } from "vue-router";

const routes = [
    {
        path: '/',
        name: 'IndexPage',
        component: () => import('../views/index/IndexPage.vue'),
        meta: { title: '工作进度表' },
    }, 
    {
        path: '/IndexPageTest',
        name: 'IndexPageTest',
        component: () => import('../views/index/IndexPageTest.vue'),
        meta: { title: '工作进度表' },
    }, 
    {
        path: '/workstationPage',
        name: 'WorkstationPage',
        component: () => import('../views/workstation/WorksPage.vue'),
        meta: { title: '工位架构图' },
    },
    
];

const router = createRouter({
    history: createWebHistory(),
    routes,
    scrollBehavior() {
        return { left: 0, top: 0 };
    },
});

// 设置页面标题
router.beforeEach((to, from, next) => {
    document.title = to.meta.title || "";
    let url = window.location.href;
    const extensionRegex = /\.txt$/; // 正则表达式匹配.txt结尾
    if (!extensionRegex.test(url)) {
        next();
    } else {
        window.location.href = url;
    }
});

export default router;
